<?php

namespace app\common\logic;

use think\Db;

/**
 * 视频操作
 * Class SendLogic
 */
class SyncVideoLogic extends Logic
{
    public static function process()
    {
        $video_db = Db::name('v_video');
        $list = $video_db->where([
            'size' => ['lt', 1],
            'is_save' => 1,
            'creation_time' => ['eq', ''],
        ])->limit(0, 5)->order('weight asc')->select();

        foreach ($list as $v) {
            $video_db->where('video_id', $v['video_id'])->setInc('weight');

            $info = VodLogic::get_video_info($v['video_id']);

            if (isset($info->Video) && isset($info->Video->Size) && $info->Video->Size > 0) {
                $data = [
                    'cover_image' => isset($info->Video->CoverURL) ? $info->Video->CoverURL : '',
                    'update_time' => $info->Video->ModificationTime,
                    'creation_time' => $info->Video->CreationTime,
                    'status' => $info->Video->Status,
                    'duration' => $info->Video->Duration,
                    'size' => $info->Video->Size,
                ];

                $video_db->where('video_id', $v['video_id'])->update($data);
            }
        }
    }
}